package net.viralpatel.spring3.controller;
 
import net.viralpatel.spring3.form.Contact;    
import org.springframework.stereotype.Controller;  
import org.springframework.validation.BindingResult;  
import org.springframework.web.bind.annotation.ModelAttribute;  
import org.springframework.web.bind.annotation.RequestMapping;   
import org.springframework.web.bind.annotation.RequestMethod;  
import org.springframework.web.bind.annotation.SessionAttributes;  
import org.springframework.web.servlet.ModelAndView;    
import org.apache.log4j.Logger;


@Controller  
@SessionAttributes public class ContactController {     
    
    @RequestMapping(value = "/addContact", method = RequestMethod.POST)   
    public String addContact(@ModelAttribute("contact")   
                        Contact contact, BindingResult result) { 
    	
    	Logger log = Logger.getLogger(this.getClass());		// Logger객체를 얻고
    	log.debug("================ Method Name : hello");	// 실제로 로그를 찍는 부분입니다.
    	

    	
        System.out.println("First Name:" + contact.getFirstname() +            
                        "Last Name:" + contact.getLastname());       
        return "redirect:contacts.dp";      
    }     
    
    @RequestMapping("/contacts")      
    public ModelAndView showContacts() { 
    	//1st param : response object - like filename...
    	//2nd param : send map object name
    	//3rd param : send map object value
        return new ModelAndView("contact", "command", new Contact());     
    }  
}   